% TABLE2B.M

clear;
randn('seed',123)

% Table 2b: Daily WTI price, 1983-2008
load data2b.txt;
varx=data2b(:,3); % Variance of the n individual regressors

% Variance of dependent variable in original joint regression
vary=5.837638;             
    
% Original regressor matrix for joint regression excluding intercept
load X2b.txt; [T,n]=size(X2b);

nrep=100000;                           % Simulation trials -> inf
for r=1:nrep

    y=sqrt(vary).*randn(T,1);
    X=zeros(size(X2b));
    for i=1:T
        for j=1:n
            if X2b(i,j)~=0
                X(i,j)=sqrt(varx(j,1)).*randn(1,1);
            end;
        end;
    end;
    
    % Take supremum over n t-statistics for each trial i:
    tstat=olsjoint(y,[ones(T,1) X]); 
    tmax(r,1)=max(tstat);
    clear y X tstat;
end;

% Compute 5% and 10% one-sided critical values of the distribution of the 
% sup-t-statistic allowing for data mining
%disp([n prctile(tmax,(1-0.05)*100)])
%disp([n prctile(tmax,(1-0.10)*100)])

% P-values
sum(sort(tmax)>1.25)/length(tmax)


